package com.flyme.module.base.provider.service.impl;

import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.base.client.entity.SysFeedback;
import com.flyme.module.base.client.entity.SysWorkCourse;
import com.flyme.module.base.client.enums.WorkingYearEnum;
import com.flyme.module.base.provider.mapper.SysFeedbackMapper;
import com.flyme.module.base.provider.mapper.SysWorkCourseMapper;
import com.flyme.module.base.provider.service.SysFeedbackService;
import com.flyme.module.base.provider.service.SysWorkCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: zyf
 * @date: 2018/10/24 16:33
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysFeedbackServiceImpl extends BaseServiceImpl<SysFeedbackMapper, SysFeedback> implements SysFeedbackService {

    @Autowired
    private SysFeedbackMapper feedbackMapper;

    /**
     * 根据用户查询反馈留言
     */
    public List<EntityMap> selectByUser(String accountInfoId, PagerInfo pagerInfo){
        pagerInfo.setPageSize(25);
        CriteriaQuery queryWrapper = new CriteriaQuery<EntityMap>(pagerInfo);
        queryWrapper.select("content,type,createTime,title");
        queryWrapper.eq("userId", accountInfoId);
        queryWrapper.orderByAsc("createTime");
        queryWrapper.getSqlSegment();
        return (List<EntityMap>) pageList(queryWrapper).getRows();
    }

    /**
     * 查询
     */
    public List<EntityMap> getAll(IPage page){
        return feedbackMapper.getAll(page);
    }

    /**
     * 根据用户id改变回复记录状态
     */
    public boolean editStatus(Long userId){
        UpdateWrapper p = new UpdateWrapper();
        return update(p.set(true, "isRead", 1).eq(true, "userId", userId).eq(true, "isRead", 0));
    }

    /**
     * 根据用户统计未查看的平台回复
     */
    public Integer countByUser(Long userId){
        return count(q().eq(true, "userId", userId).eq(true, "isRead", 0));
    }

    public Integer countByUser2(Long userId){
        return count(q().eq(true, "userId", userId));
    }
}
